﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using RibbonEditor.Templates;

namespace RibbonEditor.CommandUIDefinitionClasses
{
    class UIDefinitionHelper
    {
        internal static ICommandUIDefinition GetCommandUIDefFromXml(XmlNode node)
        {
            ICommandUIDefinition uiDefinition = null;

            switch (node.Name)
            {
                case "Button":
                    uiDefinition = new RibbonEditor.CommandUIDefinitionClasses.Button(node);
                    break;
                case "CheckBox":
                    uiDefinition = new RibbonEditor.CommandUIDefinitionClasses.CheckBox(node);
                    break;
                case "ColorPicker":
                    uiDefinition = new RibbonEditor.CommandUIDefinitionClasses.ColorPicker(node);
                    break;
                case "Combobox":
                    uiDefinition = new RibbonEditor.CommandUIDefinitionClasses.ComboBox(node);
                    break;
                case "ContextualGroup":
                    uiDefinition = new RibbonEditor.CommandUIDefinitionClasses.ContextualGroup(node);
                    break;
                case "Controls":
                    uiDefinition = new RibbonEditor.CommandUIDefinitionClasses.Controls(node, true);
                    break;
                case "DropDown":
                    uiDefinition = new RibbonEditor.CommandUIDefinitionClasses.DropDown(node);
                    break;
                case "FlyoutAnchor":
                    uiDefinition = new RibbonEditor.CommandUIDefinitionClasses.FlyoutAnchor(node);
                    break;
                case "Gallery":
                    uiDefinition = new RibbonEditor.CommandUIDefinitionClasses.Gallery(node);
                    break;
                case "GalleryButton":
                    uiDefinition = new RibbonEditor.CommandUIDefinitionClasses.GalleryButton(node);
                    break;
                case "Group":
                    uiDefinition = new Group(node);
                    break;
                case "Groups":
                    uiDefinition = new Groups(node);
                    break;
                //case "GroupTemplate":
                //    uiDefinition = new GroupTemplate(node);
                //    break;
                case "InsertTable":
                    uiDefinition = new InsertTable(node);
                    break;
                case "Label":
                    uiDefinition = new RibbonEditor.CommandUIDefinitionClasses.Label(node);
                    break;
                case "MaxSize":
                    uiDefinition = new MaxSize(node);
                    break;
                case "Menu":
                    uiDefinition = new RibbonEditor.CommandUIDefinitionClasses.Menu(node);
                    break;
                case "MenuSection":
                    uiDefinition = new MenuSection(node);
                    break;
                case "MRUSplitButton":
                    uiDefinition = new MRUSplitButton(node);
                    break;
                case "Scale":
                    uiDefinition = new Scale(node);
                    break;
                case "Scaling":
                    uiDefinition = new Scaling(node);
                    break;
                case "Spinner":
                    uiDefinition = new Spinner(node);
                    break;
                case "SplitButton":
                    uiDefinition = new SplitButton(node);
                    break;
                case "Tab":
                    uiDefinition = new Tab(node);
                    break;
                case "TextBox":
                    uiDefinition = new RibbonEditor.CommandUIDefinitionClasses.TextBox(node);
                    break;
                case "ToggleButton":
                    uiDefinition = new ToggleButton(node);
                    break;
                default:
                    throw new Exception("Unsupported CommandUIDefinition type!");
            }

            return uiDefinition;
        }
        
        internal static IControlsChild GetControlsChildFromXml(XmlNode node)
        {
            IControlsChild icControl = null;

            switch (node.Name)
            {
                case "Button":
                    icControl = new RibbonEditor.CommandUIDefinitionClasses.Button(node);
                    break;
                case "CheckBox":
                    icControl = new RibbonEditor.CommandUIDefinitionClasses.CheckBox(node);
                    break;
                case "ColorPicker":
                    icControl = new RibbonEditor.CommandUIDefinitionClasses.ColorPicker(node);
                    break;
                case "Combobox":
                    icControl = new RibbonEditor.CommandUIDefinitionClasses.ComboBox(node);
                    break;
                case "DropDown":
                    icControl = new RibbonEditor.CommandUIDefinitionClasses.DropDown(node);
                    break;
                case "FlyoutAnchor":
                    icControl = new RibbonEditor.CommandUIDefinitionClasses.FlyoutAnchor(node);
                    break;
                case "GalleryButton":
                    icControl = new RibbonEditor.CommandUIDefinitionClasses.GalleryButton(node);
                    break;
                case "InsertTable":
                    icControl = new InsertTable(node);
                    break;
                case "Label":
                    icControl = new RibbonEditor.CommandUIDefinitionClasses.Label(node);
                    break;
                case "MRUSplitButton":
                    icControl = new MRUSplitButton(node);
                    break;
                case "Spinner":
                    icControl = new Spinner(node);
                    break;
                case "SplitButton":
                    icControl = new SplitButton(node);
                    break;
                case "TextBox":
                    icControl = new RibbonEditor.CommandUIDefinitionClasses.TextBox(node);
                    break;
                case "ToggleButton":
                    icControl = new ToggleButton(node);
                    break;
                default:
                    throw new Exception("Unsupported CommandUIDefinition type!");
            }

            return icControl;
        }
    
    }
}
